package com.winspread.app.hitl

import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.winspread.app.R
import com.winspread.app.databinding.ActivityHiltBinding
import com.winspread.app.hitl.binds.BookModelCondition
import com.winspread.app.hitl.binds.BookModelSingle
import com.winspread.app.hitl.binds.IBook
import com.winspread.app.hitl.room.Book
import com.winspread.app.hitl.room.BookDao
import com.winspread.mvvm.base.vm.BaseNotVmActivity
import com.winspread.mvvm.util.click
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Named

@AndroidEntryPoint
class HiltActivity : BaseNotVmActivity<ActivityHiltBinding>(R.layout.activity_hilt) {

    init {
        //关闭沉浸式
        initImmersionBar(statusBarFont = true, isBar = false)
    }


    @Inject
    lateinit var netDataSource: NetDataSource

    @Inject
    @field:[Named("BOOK")]
    lateinit var bookDao: BookDao

    @Inject
    @field:[Named("BOOKTEST")]
    lateinit var bookDaoTest: BookDao

    @BookModelSingle
    @Inject
    lateinit var iBook: IBook


    @BookModelCondition
    @Inject
    lateinit var iBookCondition: IBook


    private val fooViewModel : FooViewModel by  viewModels()




    override fun initView() {
        super.initView()
        netDataSource.test()


        binding.but1.click {
            lifecycleScope.launch(Dispatchers.IO) {
                bookDao.insertAll(Book("sss"))
                fooViewModel.getP()

            }
        }

        binding.but2.click {
            lifecycleScope.launch(Dispatchers.IO) {
                bookDaoTest.insertAll(Book("sss"))
//                iBook.saveBook("wsqs")
//                iBookCondition.saveBook("Android艺术")
            }
        }

    }


}